using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using Kypris2.CoreElements;

using Jamila2.CoreElements;
using Jamila2.Tools;

namespace GonzalesCore.CoreElements
{
    public enum ApprovingRoute { Normal, MultiLevel, Exception }

    public class SystemUser : Kypris2.CoreElements.LoginUser, IElement
    {
        #region Project Specific Properties

        public bool ApprovalCheckPoint = false; // set this if routing check point is here
        public SystemUser PersonnelReportTo = null; // manager report to, claim routing will based on this
        public LoginUser ReviewOnBehalfBy = null; 
        public string JobTitle = "";
        public string ActiveDirectoryDistinguisedName = ""; // unique readable name in Active Directory
        public ApprovingRoute AppRoute = ApprovingRoute.Normal;
        public new GonzalesCompany FromCompany = null;
        public string UserGreeting = "";
        public int ApproverLevel = 0; // only if this user is an approver
        public decimal WeeklyLimit = 0;
        public string CreditCardNo = "";
        public string LDAP = "";
        
        public Currency ApprovingCurrency = null;
        public decimal ApprovingLimit = 0;

        public bool IsApprover = false;
        public bool IsAuthorizationPersonnel = false;
        public bool IsFinanceAdmin = false;
        public bool IsFinanceApprover = false;

        public bool IsITAdmin = false;
        public bool IsPowerAdmin = false;

        public new bool IsAdmin
        {
            get
            {
                return (IsITAdmin || IsPowerAdmin || IsFinanceAdmin);
            }
        }

        public bool NoApprover = false;
        public bool NoAuthorizer = false;

        public DateTime JoinDate = DateTime.MinValue;

        public Language PreferedLanguage = null;
        public TypeOfDateFormat PreferedDateFormat = TypeOfDateFormat.DDMMYYYY;
        public Currency DefaultCurrency = null;

        public bool UnlimitedClaimLimit
        {
            get
            {
                return (this.WeeklyLimit == 0);
            }
        }

        #endregion

        public SystemUser()
            : base()
        {
            this.internal_id = SwissArmy.UniqueID();
        }

        public SystemUser(string DisplayName)
            : base()
        {
            this.internal_id = SwissArmy.UniqueID();
            this.display_name = DisplayName;
        }

        public SystemUser(string InternalID, string DisplayName)
            : base(InternalID)
        {
            this.internal_id = InternalID;
            this.display_name = DisplayName;
        }

    }

    public class Authoriser : SystemUser, IElement
    {
        public int Level = 0;
        public Currency LimitCurrency = null;
        public decimal MaxLimit = 0, MinLimit = 0;

        public Authoriser(string DisplayName)
            : base(DisplayName)
        {
        }

        public Authoriser(string InternalID, string DisplayName)
            : base(InternalID, DisplayName)
        {
        }

    }

    public class FinanceApprover : SystemUser, IElement
    {
        public int Level = 0;
        public Currency LimitCurrency = null;
        public decimal MaxLimit = 0, MinLimit = 0;

        public FinanceApprover(string DisplayName)
            : base(DisplayName)
        {
        }

        public FinanceApprover(string InternalID, string DisplayName)
            : base(InternalID, DisplayName)
        {
        }

    }

    public class SystemUsers : CollectionBase
    {
        public SystemUser this[int index]
        {
            get
            {
                return ((SystemUser)List[index]);
            }
            set
            {
                List[index] = value;
            }
        }

        public int Add(SystemUser value)
        {
            return (List.Add(value));
        }

        public int IndexOf(SystemUser value)
        {
            return (List.IndexOf(value));
        }

        public void Insert(int index, SystemUser value)
        {
            List.Insert(index, value);
        }

        public void Remove(SystemUser value)
        {
            List.Remove(value);
        }
    }
}
